using System;
using System.Collections.ObjectModel;

namespace MvvmBase.ViewModel
{
    public class ModelJobWithParameter<TResult> : ModelJob
    {
        internal ModelJobWithParameter(ObservableCollection<ModelJobEntry> jobQueue, ModeJobMode mode) : base(jobQueue, mode)
        {
        }

        public new event EventHandler<ModelJobReleaseEventArgs<TResult>> Released;
        public void Release(TResult result)
        {
            ReleaseAndCallEvent();
            OnReleased(result);
        }

        [Obsolete]
        public override void Release()
        {
            throw new InvalidOperationException("You must provide the parameter for this object");
        }

        protected void OnReleased(TResult result)
        {
            EventHandler<ModelJobReleaseEventArgs<TResult>> handler = Released;
            if (handler != null)
                handler(this, new ModelJobReleaseEventArgs<TResult>(result));
        }
    }
}